
var ItemJson={};//货品详情
var supplierJson={};//供应商详情
var imgs;
var supplier;
var RATE=Number($.cookie('RingRate'));//汇率
var app_url=location.origin;
var MOBILE=true;
var TEAM=0;
var PlaceOrder=false;//代下单
var imgArray=[];//大图数组
var typeNo_id=0;
var styleNo_id=""; //款号
var styleData=""; //存入款号的值
var isLogin=getcookie("CustomerID");//客户ID
(function(){
    //var inlayID= inlay_id;
    var item = null;
    var inlayItem={
        init:function(){
            args = GetUrlParms();
            if(args["ID"]!=undefined){
                ringID = args["ID"];//产品ID
            }
            if(args["team"]!=undefined){
                TEAM=args["team"];//2为现货
            }
            if(args["cid"]!=undefined){
                Customer_id = args["cid"];
                PlaceOrder=true;//代下单
            }

            if(args["typeNo"]!=undefined){
                typeNo_id = args["typeNo"];
            }

            if(args["styleNo"]!=undefined){
                styleNo_id = args["styleNo"];
            }

            this.bindEvent();
            this.loadInlayItem();
            this.loadStyleInlayItem();
        },
        bindEvent:function(){
            var self=this;
            if(APP){
                if(isLogin==null || isLogin=="(null)" ||!isLogin || isLogin=='nil'){
                    $("#add_list").hide();
                }
            }
            //立即购买
            $("#edit_btn_box").on("click","#add_to_order",function(){
                var orderJson={};
                orderJson.orderID = [];
                orderJson.type="inlays";
                orderJson.PriceUSD=$("#dataUSD").text();
                orderJson.PriceRMB=$("#dataRMB").text();


                orderJson.orderID.push(ringID);
                if(PlaceOrder==true){
                    var link_url="/Customer/SubmitDiaOrder?type=3&cid="+Customer_id;
                }else{
                    var link_url="/Customer/SubmitDiaOrder?type=3";
                }
                if(APP){
                    var appJson={};
                    appJson.title="确认下单";
                    appJson.url=app_url+link_url;
                    appJson.content=JSON.stringify(orderJson);
                    YiYi_APP.submitOrder(JSON.stringify(appJson))
                }else{
                    var action=link_url;
                    form = $("<form method='post' id='params_form' action='"+action+"'>"+
                        "<input type='text' value='"+JSON.stringify(orderJson)+"' name='params'></form>")
                    $("#form_box").html(form);
                    $("#params_form").submit();
                }
            });
            //删除产品
            $("#edit_btn_box").on("click","#inlay_delete",function(){
                myApp.confirm('您确定要删除该货品吗？', function () {
                    self.DelInlays();
                });
            });

            //app编辑
            $("#edit_btn_box").on("click","#edit_btn",function(){
                var url=$(this).attr("data-href");
                //var title=$("#app_title").text();
                if(APP){
                    var editJson={};
                    editJson.url=app_url+url;
                    editJson.title="成品编辑";
                    YiYi_APP.editGoods(JSON.stringify(editJson));
                }else{
                    location.href=url;
                }
            });
            //app点击证书
            $("#inlays_detail").on("click","#app_cert_link",function(){
                app_linkCert();
            });
//			$("#look_img").on("click",function(){
//				//big_img大图图片集合
//				var index=$("#Indicators").find("span.current").index();
//				if(APP){
//					var ProductImg={};
//					 ProductImg['images']=big_img;
//					 ProductImg['index']=index;
//					YiYi_APP.showImages(JSON.stringify(ProductImg));
//				}else{
//					var big_src=big_img[index];
//					window.open(big_src, "_blank");
//				}
//			});


            //相同款号
            $("#inlays_detail").on('click','#styleNo',function(){
                myApp.popup(".rings_box");
                if(TEAM == 1 || TEAM == 2){
                    $('.add_rings_buy').hide();
                    $('.operation').hide();
                }

                $("#styleNo_tbody").html('');
                var str="";
                for(var i=0;i<styleData.length;i++){
                    var row=styleData[i];
                    var status=row.Status;
                    str+='<tr >'+
                        '<td>' +GetText("inlays",row.Category,row.Material,"Material")+ '</td>'+
                        '<td>'+row.Measurement+'</td>'+
                        '<td>'+formatRMBPrice(row.Price)+'</td>'+
                        '<td>'+row.MainWeight+'</td>';
                        if(TEAM == 0 || TEAM ==3){
                            if(status == 1 || status == 3 || status == 6){
                                str+='<td><input type="checkbox" class="checkboxs" id="checkOne" lang="'+row.ID+'" style="zoom:150%"></td>';
                            }else {
                                str+='<td></td>';
                            }
                        }
                        str+='</tr>';
                }
                $('#styleNo_tbody').append(str)
            });

            //相同款号立即订购
            $(".rings_box").on('click','.add_rings_buy',function(){
                var  params = {};
                var cartlistCb = $("#styleNo_tab tbody input[type='checkbox']:checked"); //tbody中checked的
                var _IDs = "";

                for(var i = 0; i < cartlistCb.length; i++) {
                    if(i == 0)
                        _IDs += cartlistCb[i].lang;
                    else
                        _IDs += "," + cartlistCb[i].lang;
                }

                if(TEAM==0){//客户端
                    params.CustomerID = CustomerID;
                    params.OrderType = 1;
                }else if(TEAM==3){//代下单
                    params.CustomerID = Customer_id;
                    params.OrderType = 2;
                    params.UserID=UserID;
                }

                params.GoodsType=3;
                params.RingIDs=_IDs;
                if(cartlistCb.length!=0){
                    $.ajax({
                        url: "/Team/SubmitOrderNew", //提交地址
                        type: "POST",//提交方式
                        data: JSON.stringify(params),
                        contentType: "application/json; charset=utf-8",
                        success: function (result) {
                            var _result = eval('(' + result + ')');//eval()解析单个json对象
                            if(_result.msgcode==false){
                                myApp.alert(_(_result.msginfo));
                            }else{
                                var successful=_result.msginfo.Successful; //成功条目
                                var Failed=_result.msginfo.Failed; //失败条目
                                myApp.alert(_("成功条目")+"：" + successful +","+ _("失败条目")+"："  + Failed);
                                $('.rings_box').hide();
                            }
                        }
                    });

                }else{
                    myApp.alert("请勾选需要勾选的商品")
                }
            });

            //相同款号加入购物车
            $(".rings_box").on('click','.add_rings_cart',function(){
                var  params = {};
                var cartlistCb = $("#styleNo_tab tbody input[type='checkbox']:checked"); //tbody中checked的
                var _IDs = "";

                for(var i = 0; i < cartlistCb.length; i++) {
                    if(i == 0)
                        _IDs += cartlistCb[i].lang;
                    else
                        _IDs += "," + cartlistCb[i].lang;
                }
                params.CartType = 1;
                if(TEAM==0){//客户端
                    params.CustomerID = CustomerID;
                }
                params.IDs=_IDs;
                if(cartlistCb.length!=0){
                    $.ajax({
                        url: "/Team/AddRingsCart", //提交地址
                        type: "POST",//提交方式
                        data: JSON.stringify(params),
                        contentType: "application/json; charset=utf-8",
                        success: function (result) {
                            var _result = eval('(' + result + ')'); //eval()解析单个json对象
                            var successful=_result.succ; //成功条目
                            var Failed=_result.fail; //失败条目
                            myApp.alert(_("成功条目")+"：" + successful +","+ _("失败条目")+"："  + Failed);
                            $('.rings_box').hide();
                        }
                    });

                }else{
                    myApp.alert("请勾选需要勾选的商品")
                }
            });



            //加入购物车
            $("#edit_btn_box").on("click","#add_to_cart", function () {
                var ringId = $(this).attr("data-id");
                self.AddCart(ringId);
            });
            //继续逛逛
            $(".page").on("click","#go_shop",function(){
                var linkUrl="/Customer/Ring?team=0";
                $("#cart-tip").remove();
                if(APP){
                    YiYi_APP.finish();
                }else{
                    location.href=linkUrl;
                }
            });
            //去购物车
            $(".page").on("click","#go_cart",function(){
                var linkUrl="/Customer/RingCart";
                $("#cart-tip").remove();
                if(APP){
                    var appJson={};
                    appJson.title="购物车";
                    appJson.function_menu="shopping_cart";
                    appJson.url=app_url+linkUrl;
                    YiYi_APP.showExistingPage(JSON.stringify(appJson));
                }else{
                    location.href=linkUrl;
                }
            });
            //跳到证书
            $("#inlays_detail").on("click","a.cert_link_btn",function(){
                var link_url=$(this).attr("data-href");
                if(APP){
                    var appJson={};
                    appJson.title="证书";
                    appJson.url=app_url+link_url;
                    YiYi_APP.showNewPage(JSON.stringify(appJson));
                }else{
                    location.href=link_url;
                }
            });
        },

        //根据款号加载详情
        loadStyleInlayItem:function(){
            var submitJson={};
            submitJson.StyleNo=styleNo_id;
            submitJson.GoodsType=3;
            if(TEAM==0){
                submitJson.CustomerID = CustomerID;//客户ID
            }
            if(TEAM==3){
                submitJson.CustomerID = Customer_id;
            }

            $.ajax({
                url: "/Team/GetProductData",//提交地址
                type: "POST",//提交方式
                data: JSON.stringify(submitJson),
                contentType: "application/json; charset=utf-8",
                success: function (result) {
                    var res=JSON.parse(result);
                    styleData=res.msginfo.rows; //相同款号所有值
                    for(var i=0;i<styleData.length;i++){
                        $("#inlays_detail #styleNo").html(styleData.length);
                    }
                }
            });

        },

        //加载详情
        loadInlayItem:function(){
            // myApp.showIndicator();//显示加载中
            var self=this;
            // var das=JSON.parse(localStorage.getItem('das')) || '';

            var submitJson={};
            submitJson.ID=ringID;
            submitJson.GoodsType=3;
            if(TEAM == 0){
                submitJson.CustomerID=CustomerID;
            }
            if(TEAM ==3){
                submitJson.CustomerID=Customer_id;
            }
            // if(TEAM==0){
            //     submitJson.CustomerID = CustomerID;//客户ID
            //     if(das){
            //         var requsetProduct={};
            //         requsetProduct.ProductNo=das.productno;
            //         requsetProduct.ProductSupplier=das.productsupplier;
            //         requsetProduct.CustomerID=CustomerID;
            //         requsetProduct.GoodsType=3;
            //         console.log(requsetProduct)
            //         $.ajax({
            //             url: "/Customer/ProductSearch",//提交地址
            //             type: "POST",//提交方式
            //             data: JSON.stringify(requsetProduct),
            //             contentType: "application/json; charset=utf-8",
            //             success: function (result) {
            //
            //             }
            //         });
            //     };
            //
            // }
            if(TEAM==2){
                submitJson.IsMyStock=true;
            }
            $.ajax({
                url:'/Team/GetProductData',
                type:'POST',
                data: JSON.stringify(submitJson),
                dataType:'JSON',
                contentType: "application/json; charset=utf8",
                timeout: 30000, //超时时间：30秒
                success:function(result){
                    var res=eval('(' + result + ')');
                    ItemJson=res;
                    if (res.msgcode == true) {
                        var datas=res.msginfo.rows;
                        var data =datas[0];
                        //self.LoadSupplierDetail(data.Supplier);
                        imgs = data.Images.split("|");
                        var lis="";
                        var app_lis=[];
                        var span_lis="";
                        var jsonImg={
                            images:[],
                            videos:''
                        }
                        for (var i=0; i< imgs.length;i++) {
                            jsonImg.images.push(imgs[i])
                            if (imgs[i].length > 50) {
                                var span_li='<span data-val="'+i+'"></span>';
                                span_lis+=span_li;
                                var li = '<li><a href="'+imgs[i] +'"><img src="' + imgs[i] + '" class="image' + i + '"/></a></li>';
                                lis += li;
                                var big = imgs[i].replace('800x800', '1920x1920');
                                var app_li={url: imgs[i], caption: i};
                                app_lis.push(app_li);
                                imgArray.push(big);
                            }else{
                                var img_null='/images/no_img.jpg';
                                var lis='<li><a href="/images/no_img.jpg"><img src="'+img_null+'" class="image' + i + '"/></a></li>';
                                var app_li={url: img_null, caption: i};
                                app_lis.push(app_li);
                                imgArray.push(img_null)
                            }
                        }
                        // var userAgent=navigator.userAgent;
                        // if(APP && userAgent.indexOf('Android')!=-1){
                        //     $("#MainContent").hide();
                        //     YiYi_APP.showRotationChart(JSON.stringify(jsonImg))
                        // }else{
                            //图片列
                            $("#img_box").html(lis);
                            $("#Indicators").html(span_lis);
                            if(MOBILE){
                                (function(window, Util, PhotoSwipe){
                                    document.addEventListener('DOMContentLoaded', function(){
                                        var options = {},
                                            instance = PhotoSwipe.attach( window.document.querySelectorAll('.ps-carousel-item img'), options );
                                    }, false);
                                    Util.Events.domReady(function(e){
                                        var instance, indicators;
                                        instance = PhotoSwipe.attach(
                                            app_lis,
                                            {
                                                target: window.document.querySelectorAll('#PhotoSwipeTarget')[0],
                                                preventHide: true,
                                                getImageSource: function(obj){
                                                    return obj.url;
                                                },
                                                getImageCaption: function(obj){
                                                    return obj.caption;
                                                }
                                            }
                                        );
                                        indicators = window.document.querySelectorAll('#Indicators span');
                                        instance.addEventHandler(PhotoSwipe.EventTypes.onDisplayImage, function(e){
                                            var i, len;
                                            for (i=0, len=indicators.length; i<len; i++){
                                                indicators[i].setAttribute('class', '');
                                            }
                                            indicators[e.index].setAttribute('class', 'current');
                                        });
                                        instance.show(0);
                                    });
                                }(window, window.Code.Util, window.Code.PhotoSwipe))
                            }
                            //显示图片end
                        // }



                        //显示视频
                        $('#video_div').find('video').attr('src',data.Videos)
                        $('#video_div').find('.zy_wrap').css('height','250px')


                        //详情参数
                        LoadInlaysItemHtml(data);
                        //管理页面有编辑和删除按钮
                        var addCart;
                        if(typeNo_id==0){
                            addCart='';
                        }else{
                            if(APP){
                                if(isLogin==null || isLogin=="(null)" ||!isLogin || isLogin=='nil'){
                                    addCart="";
                                }else{
                                    addCart= '<a href="#" style="margin-right:20px;" id="add_to_cart" data-id='+data.ID+'>加入购物车</a>'
                                }
                            }else{
                                addCart= '<a href="#" style="margin-right:20px;" id="add_to_cart" data-id='+data.ID+'>加入购物车</a>'
                            }
                        }
                        if(APP){
                            if(isLogin==null || isLogin=="(null)" ||!isLogin || isLogin=='nil'){
                                    var editHtmlStr= [].join('');
                            }else{
                                if(data.Status==1 || data.Status==3 || data.Status==6){
                                    var editHtmlStr= [
                                        addCart,
                                        '<a href="#" id="add_to_order">立即购买</a>'].join('');
                                }else{
                                    var editHtmlStr=['<p style="color:red" >'+StatusFormat(data.Status)+'状态,不能下单</p>'].join('');
                                }
                            }
                        }else{
                            if(data.Status==1 || data.Status==3 || data.Status==6){
                                var editHtmlStr= [
                                    addCart,
                                    '<a href="#" id="add_to_order">立即购买</a>'].join('');
                            }else{
                                var editHtmlStr=['<p style="color:red" >'+StatusFormat(data.Status)+'状态,不能下单</p>'].join('');
                            }
                        }

                        if(data.Status==1 || data.Status==3 || data.Status==6){
                            var placeHtmlStr= ['<a href="#" id="add_to_order">'+_("代购买")+'(<b style="font-size:12px" id="_realName">'+getUrlParam('userName')+'</b>)'+'</a>'].join('');
                        }else{
                            var placeHtmlStr=['<p style="color:red" >'+StatusFormat(data.Status)+'状态,不能下单</p>'].join('');
                        }

                        var myEditHtml=[
                            '<a href="#" id="edit_btn" data-href="/Team/RingManagement?ID=',data.ID,'&type=3" style="margin-right:20px;">编辑</a>',
                            '<a id="inlay_delete" href="#">删除</a>'].join('');
                        if(TEAM==0){//客户端的列表页
                            $("#edit_btn_box").html(editHtmlStr);
                        }else if(TEAM==2){//现货
                            $("#edit_btn_box").html(myEditHtml);

                        }else if(TEAM==3){//代下单
                            $("#edit_btn_box").html(placeHtmlStr);
                        }
                        //   @*主题色start*@
                        $(document.createElement("script")).attr("src","/Js/ThemesColor.js").appendTo("html");
                        //  @*主题色end*@
                        item = res;
                        //放大图片
                        var myPhotoBrowserStandalone = myApp.photoBrowser({
                            photos : imgArray,
                            backLinkText: '返回',
                            ofText:"/",
                        });
                        $$('#look_img').on('click',function () {
                            var index=$("#Indicators").find("span.current").index();
                            if(APP){
                                var ProductImg={};
                                ProductImg['images']=imgArray;
                                ProductImg['index']=index;
                                YiYi_APP.showImages(JSON.stringify(ProductImg));
                            }else{
                                myPhotoBrowserStandalone.open(index);
                            }
                        });


                    }else{
                        myApp.alert(res.result);
                    }
                    myApp.hideIndicator();//隐藏加载中
                },
                error:function(a,b,c){
                    myApp.alert(c);
                }
            });
        },

        //刪除成品
        DelInlays:function() {
            myApp.showIndicator();//显示加载中
            $.ajax({
                url: "/Team/DelProductData",//提交地址
                type: "POST",//提交方式
                data: "{'id':'" +ringID + "','GoodsType':'3'}",
                contentType: "application/json; charset=utf-8",
                success: function (result) {
                    var jsonResult = eval('(' + result + ')');//eval()解析单个json对象
                    if (jsonResult && jsonResult.result) {
                        myApp.alert('删除成功！', function () {
                            if(APP){
                                YiYi_APP.finish();
                            }else{
                                location.href = "/Team/MyRing?team=2";
                            }
                        });
                    } else {
                        myApp.alert(jsonResult.msg);
                    }
                    myApp.hideIndicator();//隐藏加载中
                }
            });
        },
        //加入购物
        AddCart:function (ringId) {
            //InventoryIDs值组装 _inventoryIDs="232,324"
            myApp.showPreloader('正在加入中，请稍等...');
            var addCart = {};
            addCart.CustomerID = CustomerID;
            addCart.CartType = 1;
            addCart.IDs = ringId;
            $.ajax({
                url: "/Customer/AddRingsCart",//提交地址   /customer/ringcart
                type: "POST",//提交方式
                data: JSON.stringify(addCart),
                contentType: "application/json; charset=utf-8",
                success: function (result) {
                    var res=eval('('+result+')');
                    myApp.hidePreloader();
                    if(res.msgcode==true){
                        var strTip = "";
                        strTip = '<div class="tip-box order-tip" id="cart-tip">'+
                            '<div class="tip-text">'+
                            '<div class="tip-title">'+
                            '<div class="">加入购物车成功</div>'+
                            '</div>'+
                            '<div class="buttons">'+
                            '<span class="btn-left" id="go_shop"><a href="#">继续逛逛</a></span>'+
                            '<span class="btn-right" id="go_cart"><a href="#">去购物车</a></span>'+
                            '</div>'+
                            '</div>'+
                            '</div>';
                        $("#app_no_header").after(strTip);
                        $(".tip-box").show();
                        //   @*主题色start*@
                        $(document.createElement("script")).attr("src","/Js/ThemesColor.js").appendTo("html");
                        //  @*主题色end*@
                    }else{
                        myApp.alert(res.msginfo);
                    }
                }
            });
        },

    }
    inlayItem.init();

}());

//详情数据

function LoadInlaysItemHtml(data){
    var type=data.Category;
    var inlays_detail=[];
    var supplier ="";
        if(TEAM==1 || TEAM==3){
            if(isHideSupplier == "1"){
                    supplier = '<div class="tr tr_block">'+
                        '<div class="td td_str">供应商：</div>'+
                        '<div class="td td_data">'+(data.Supplier)+'</div>'+
                        '</div>';
            }
        }



    //显示视频
    var videoStr='';
    videoStr+='<div class="tr">'+
        '<div class="td td_str"><img src="/images/imageIcon.png" style="20px;width:20px"  class="ImgBtn"></div>';
    if(data.Videos){

        videoStr+= '<div class="td td_data"><img src="/images/videoIcon.png" data-videos="'+data.Videos+'" style="height:20px;width:20px" class="VideoBtn"></div>';
    }
    videoStr+= '</div>';

    var ringPrice="";
    if(TEAM==2){
        ringPrice= '<div class="detail_left">'+
            '<div class="tr">'+
            '<div class="td td_str">采购汇率：</div>'+
            '<div class="td td_data" id="purchaseExchange">'+data.PurchaseExchange+'</div>'+
            '</div>'+
            '<div class="tr">'+
            '<div class="td td_str">采购时间：</div>'+
            '<div class="td td_data" id="purchaseTime">'+YearDateFormat(data.PurchaseTime)+'</div>'+
            '</div>'+
            '<div class="tr">'+
            '<div class="td td_str">发货时间：</div>'+
            '<div class="td td_data" id="shipTime">'+YearDateFormat(data.ShipTime)+'</div>'+
            '</div>'+
            '<div class="tr CurrentUSD">'+
            '<div class="td td_str">原&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$：</div>'+
            '<div class="td td_data price_color" id="dataUSD">'+returnPrice(data)+'</div>'+
            '</div>'+
            '<div class="tr CurrentUSD">'+
            '<div class="td td_str">采&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$：</div>'+
            '<div class="td td_data price_color" id="dataUSD">'+returnPurUSDPrice(data)+'</div>'+
            '</div>'+
            '</div>'+
            '<div class="detail_right">'+

            '<div class="tr">'+
            '<div class="td td_str">采购供应商：</div>'+
            '<div class="td td_data" id="purchaseSupplier">'+data.PurchaseSupplier+'</div>'+
            '</div>'+
            '<div class="tr">'+
            '<div class="td td_str">付&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;款：</div>'+
            '<div class="td td_data">'+formatReceiptStatus(data.ReceiptStatus)+'</div>'+
            '</div>'+
            '<div class="tr">'+
            '<div class="td td_str">到货时间：</div>'+
            '<div class="td td_data" id="arrivalTime">'+YearDateFormat(new Date(GetDateDiffTime(data.ArrivalTime)).getTime())+'</div>'+
            '</div>'+
            '<div class="tr CurrentRMB">'+
            '<div class="td td_str">原&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;￥：</div>'+
            '<div class="td td_data price_color" id="dataRMB">'+returnRMBPrice(data)+'</div>'+
            '</div>'+
            '<div class="tr CurrentRMB">'+
            '<div class="td td_str">采&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;￥：</div>'+
            '<div class="td td_data price_color" id="dataRMB">'+returnPurRMBPrice(data)+'</div>'+
            '</div>'+
            '</div>';
    }else{
        if(TEAM==0){
            var ringPriceDiacount='';
            if(priceRing_td_new==true){
                ringPrice= '<div class="tr_block CurrentUSD" style="width:50%;float:left">'+
                    '<div class="tr">'+
                    '<div class="td td_str">总&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;价$：</div>'+
                    '<div class="td td_data price_color" id="dataUSD">'+returnPrice(data)+'</div>'+
                    '</div>'+
                    '</div>';

            }

            if(RMBRingPrice_td_new==true){
                ringPrice+= '<div class="tr_block CurrentRMB" style="width:50%;float:left">'+
                    '<div class="tr">'+
                    '<div class="td td_str">总&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;价￥：</div>'+
                    '<div class="td td_data price_color" id="dataRMB">'+returnRMBPrice(data)+'</div>'+
                    '</div>'+
                    '</div>';
            }


            if(discountRingPrice_td_new == true){
                ringPriceDiacount= '<div class="tr_block CurrentUSD" style="width:50%;float:left">'+
                    '<div class="tr">'+
                    '<div class="td td_str">优&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;惠$：</div>'+
                    '<div class="td td_data price_color" id="dataUSD">'+formatUSDPrice((data.Price)/RATE*Discounts)+'</div>'+
                    '</div>'+
                    '</div>';
            }
            if(discountRingRMBPrice_td_new == true){
                ringPriceDiacount+='<div class="tr_block CurrentRMB" style="width:50%;float:left">'+
                    '<div class="tr">'+
                    '<div class="td td_str">优&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;惠￥：</div>'+
                    '<div class="td td_data price_color" id="dataRMB">'+formatRMBPrice(data.Price*Discounts)+'</div>'+
                    '</div>'+
                    '</div>';
            }


        }else if(TEAM==1 || TEAM==3){
            ringPrice= '<div class="tr_block CurrentUSD" >'+
                '<div class="tr">'+
                '<div class="td td_str">总&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;价$：</div>'+
                '<div class="td td_data price_color" id="dataUSD">'+returnPrice(data)+'</div>'+
                '</div>'+
                '</div>'+
                '<div class="tr_block CurrentRMB">'+
                '<div class="tr">'+
                '<div class="td td_str">总&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;价￥：</div>'+
                '<div class="td td_data price_color" id="dataRMB">'+returnRMBPrice(data)+'</div>'+
                '</div>'+
                '</div>';
        }

    }

    //货品查找权限详情start
    var seriesPower=''; //系列
	var shapePower=''; //形状
	var weightPower=''; //总重
	var mainWeightPower=''; //主石重量
	var materialPower=''; //材质
	var placePower=''; //所在地

	if(TEAM==0){
            seriesPower= '<div class="tr tr_block">'+
                '<div class="td td_str">系&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;列：</div>'+
                '<div class="td td_data">'+(data.Series)+'</div>'+
                '</div>';
            shapePower= '<div class="tr">'+
            '<div class="td td_str">形&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;状：</div>'+
            '<div class="td td_data">'+GetText("inlays",data.Category,data.MainShape,"MainShape")+'</div>'+
            '</div>';

            weightPower='<div class="tr">'+
                '<div class="td td_str">总&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;重：</div>'+
                '<div class="td td_data">'+data.Weight+'</div>'+
                '</div>';

            mainWeightPower=  '<div class="tr">'+
            '<div class="td td_str">主石重量：</div>'+
            '<div class="td td_data">'+data.MainWeight+'</div>'+
            '</div>';

            materialPower= '<div class="tr">'+
            '<div class="td td_str">材&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;质：</div>'+
            '<div class="td td_data">'+GetText("inlays",data.Category,data.Material,"Material")+'</div>'+
            '</div>';
		if(placeRing_td_new==true){
            placePower='<div class="tr">'+
                '<div class="td td_str">所&nbsp;在&nbsp;地：</div>'+
                '<div class="td td_data">'+data.Country+data.State+'</div>'+
                '</div>';
		}
        //货品查找权限详情end

	}else{
	    if(TEAM==1 || TEAM==3){
            seriesPower= '<div class="tr tr_block">'+
                '<div class="td td_str">系&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;列：</div>'+
                '<div class="td td_data">'+(data.Series)+'</div>'+
                '</div>';
            shapePower= '<div class="tr">'+
                '<div class="td td_str">形&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;状：</div>'+
                '<div class="td td_data">'+GetText("inlays",data.Category,data.MainShape,"MainShape")+'</div>'+
                '</div>';
            weightPower='<div class="tr">'+
                '<div class="td td_str">总&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;重：</div>'+
                '<div class="td td_data">'+data.Weight+'</div>'+
                '</div>';
            mainWeightPower= '<div class="tr">'+
                '<div class="td td_str">主石重量：</div>'+
                '<div class="td td_data">'+data.MainWeight+'</div>'+
                '</div>';
            materialPower= '<div class="tr">'+
                '<div class="td td_str">材&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;质：</div>'+
                '<div class="td td_data">'+GetText("inlays",data.Category,data.Material,"Material")+'</div>'+
                '</div>';
            placePower='<div class="tr">'+
                '<div class="td td_str">所&nbsp;在&nbsp;地：</div>'+
                '<div class="td td_data">'+data.Country+data.State+'</div>'+
                '</div>';
        }else if(TEAM==2){
            seriesPower= '<div class="tr tr_block">'+
                '<div class="td td_str">系&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;列：</div>'+
                '<div class="td td_data">'+(data.Series)+'</div>'+
                '</div>';
            shapePower= '<div class="tr">'+
                '<div class="td td_str">形&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;状：</div>'+
                '<div class="td td_data">'+GetText("inlays",data.Category,data.MainShape,"MainShape")+'</div>'+
                '</div>';
            weightPower='<div class="tr">'+
                '<div class="td td_str">总&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;重：</div>'+
                '<div class="td td_data">'+data.Weight+'</div>'+
                '</div>';
            mainWeightPower=  '<div class="tr">'+
                '<div class="td td_str">主石重量：</div>'+
                '<div class="td td_data">'+data.MainWeight+'</div>'+
                '</div>';
            materialPower= '<div class="tr">'+
                '<div class="td td_str">材&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;质：</div>'+
                '<div class="td td_data">'+GetText("inlays",data.Category,data.Material,"Material")+'</div>'+
                '</div>';
            placePower='<div class="tr">'+
                '<div class="td td_str">所&nbsp;在&nbsp;地：</div>'+
                '<div class="td td_data">'+data.Country+data.State+'</div>'+
                '</div>';
        }

	}

    var strStyleNo='';
    if(TEAM == 0 || TEAM == 1 || TEAM == 2 || TEAM ==3){
        strStyleNo='<div class="td td_data styleNo" id="styleNo" style="padding-left:10px;color:#0080ff;width:20px"></div>';
    }


    //空托
    if(type==1){
        inlays_detail=[
            seriesPower,
            '<div class="detail_left">',
            '<div class="tr">',
            '<div class="td td_str">款&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;号：</div>',
            '<div class="td td_data">',data.StyleNo,'</div>',
            strStyleNo,
            '</div>',
            '<div class="tr">',
            '<div class="td td_str">主石类型：</div>',
            '<div class="td td_data">',GetCategory("inlays",data.Category),'</div>',
            '</div>',
			weightPower,
			placePower,
            '<div class="tr">',
            '<div class="td td_str">出售方式：</div>',
            '<div class="td td_data">',GetText("inlays",data.Category,data.IsStock,"IsStock"),'</div>',
            '</div>',

            '</div>',
            '<div class="detail_right">',
            '<div class="tr">',
            '<div class="td td_str">货&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;号：</div>',
            '<div class="td td_data">',data.OriginSN,'</div>',
            '</div>',

			mainWeightPower,
            '<div class="tr">',
            '<div class="td td_str">副石重量：</div>',
            '<div class="td td_data">',data.SideWeight,'</div>',
            '</div>',
            '<div class="tr">',
            '<div class="td td_str">尺&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;寸：</div>',
            '<div class="td td_data td_measurement">',data.Measurement==""?"-":data.Measurement,'</div>',
            '</div>',
            '<div class="tr">',
            '<div class="td td_str">状&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;态：</div>',
            '<div class="td td_data">',GetText("inlays",data.Category,data.Status,"Status"),'</div>',
            '</div>',
            '</div>',
            '<div class="tr">',
            '<div class="td td_str">材&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;质：</div>',
            '<div class="td td_data">',GetText("inlays",data.Category,data.Material,"Material"),'</div>',
            '</div>',
            '<div class="tr tr_block tr_normal">',
            '<div class="td td_str">备&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;注：</div>',
            '<div class="td td_data">',(data.Remark),'</div>',
            '</div>',
            '<div class="tr tr_block tr_normal">',
            '<div class="td td_str">上传时间：</div>',
            '<div class="td td_data">', DateTimeFormat(data.InsertTime), '</div>',
            '</div>',supplier,
            '<div class="tr tr_block exchangeRate">',
            '<div class="td td_str">汇&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;率：</div>',
            '<div class="td td_data">',RATE,'</div>',
            '</div>',
            ringPrice,
            ringPriceDiacount,
        ].join('');
    }

    //白彩钻彩宝
    else{
        inlays_detail=[
            seriesPower,
            '<div class="detail_left">',
            '<div class="tr">',
            '<div class="td td_str">款&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;号：</div>',
            '<div class="td td_data">',data.StyleNo,'</div>',
            strStyleNo,
            '</div>',
            '<div class="tr">',
            '<div class="td td_str">主石类型：</div>',
            '<div class="td td_data">',GetCategory("inlays",data.Category),'</div>',
            '</div>',

            '<div class="tr">',
            '<div class="td td_str">尺&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;寸：</div>',
            '<div class="td td_data td_measurement">',data.Measurement==""?"-":data.Measurement,'</div>',
            '</div>',

            materialPower,
            '<div class="tr">',
            '<div class="td td_str">成品证书：</div>',
            '<div class="td td_data">',data.CertType,'</div>',
            '</div>',
            placePower,
            '<div class="tr">',
            '<div class="td td_str">出售方式：</div>',
            '<div class="td td_data">',GetText("inlays",data.Category,data.IsStock,"IsStock"),'</div>',
            '</div>',
            '<div class="tr">',
            '<div class="td td_str">状&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;态：</div>',
            '<div class="td td_data">',GetText("inlays",data.Category,data.Status,"Status"),'</div>',
            '</div>',
            '<div class="tr tr_block tr_normal">',
            '<div class="td td_str">上传时间：</div>',
            '<div class="td td_data">', DateTimeFormat(data.InsertTime), '</div>',
            '</div>',
            '</div>',
            '<div class="detail_right">',
            '<div class="tr">',
            '<div class="td td_str">货&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;号：</div>',
            '<div class="td td_data">',data.OriginSN,'</div>',
            '</div>',
            weightPower,
            shapePower,
            '<div class="tr">',
            '<div class="td td_str">主石证书：</div>',
            '<div class="td td_data">',data.MainCertType,'</div>',
            '</div>',
            videoStr,
            mainWeightPower,
            '<div class="tr">',
            '<div class="td td_str">主石颜色：</div>',
            '<div class="td td_data">',GetText("inlays",data.Category,data.MainColor,"MainColor"),'</div>',
            '</div>',TextHtml(data),
            '<div class="tr tr_block exchangeRate">',
            '<div class="td td_str">汇&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;率：</div>',
            '<div class="td td_data">',RATE,'</div>',
            '</div>',

            '</div>',
            '<div class="tr">',
            '<div class="td td_str">副石重量：</div>',
            '<div class="td td_data">',data.SideWeight,'</div>',
            '</div>',returnProcess(data),

            '<div class="tr tr_block tr_normal" style="width:50%">',
            '<div class="td td_str">备&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;注：</div>',
            '<div class="td td_data">',(data.Remark),'</div>',
            '</div>',
            '<div class="tr td_str" style="width:50%">',
            '<div class="td td_str">证 &nbsp;书&nbsp;号：</div>',
            '<div class="td td_data" data>',linkCertType(data),'</div>',
            '</div>',

            supplier,
            ringPrice,
            ringPriceDiacount,
        ].join('');
    }

    $("#inlays_detail").html(inlays_detail);
    currentShow();  //币种设置
}
//红宝和蓝宝的处理
function returnProcess(data){
    if(data.Category==4 || data.Category==5){
        return  ['<div class="tr"><div class="td td_str">处&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;理：</div>',
            '<div class="td td_data">',GetText("inlays",data.Category,data.Process,"Process"),'</div></div>'].join('');
    }

}
//无权限看到价格时的显示
function returnPrice(data){
//	if(data.Price || data.Price==0){
    return formatUSDPrice((data.Price)/RATE);
//	}else{
//		return ('权限不足');
//	}
}
function returnRMBPrice(data){
//	if(data.Price || data.Price==0){
    return formatRMBPrice(data.Price);
//	}else{
//		return ('权限不足');
//	}
}

//现货查看采购美金和人民币的转换
function returnPurUSDPrice(data){
    return formatUSDPrice(data.PurchaseUSD);
}
function returnPurRMBPrice(data){
    return formatRMBPrice(data.PurchaseRMB);
}

function TextHtml(data){
    if(data.Category==2 || data.Category==3){
        return ['<div class="tr">',
            '<div class="td td_str">主石净度：</div>',
            '<div class="td td_data">',data.MainClarity,'</div>',
            '</div>'].join('');
    }else if(data.Category>3){
        return ['<div class="tr">',
            '<div class="td td_str">产&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;地：</div>',
            '<div class="td td_data">',GetText("inlays",data.Category,data.Place,"Place"),'</div>',
            '</div>'].join('');
    }

}

//app分享用的详情
function Item_APP(){
    if(APP){
        var shareJson={};
        shareJson.title="成品"+GetCategory(ItemJson.Category);
        shareJson.text="颜色"+"："+GetText(ItemJson.Category,ItemJson.MainColor,"MainColor")+"；"+"形状"+"："+GetText(ItemJson.Category,ItemJson.MainShape,"MainShape")+"；"+
            "主石重量"+"："+ItemJson.MainWeight+"；"+("价格")+"："+ItemJson.Price+"；"+("类型")+"："+GetText(ItemJson.Category,ItemJson.Type,"Type")+"；"+
            "风格款式"+"："+GetText(ItemJson.Category,ItemJson.Style,"Style")+"；"+"材质"+"："+GetText(ItemJson.Category,ItemJson.Material,"Material")+"；"+("出售方式")+"："+GetText(ItemJson.Category,ItemJson.IsStock,"IsStock");
        imgs = ItemJson.Images.split("|");
        shareJson.images=[];
        for (var i=0; i< imgs.length;i++) {
            if (imgs[i].length > 10) {
                shareJson.images.push(imgs[i]);
            }
        }
        shareJson.url=app_url+"/"+LANGCODE+"/inlays/"+ItemJson.ID;
        shareJson.copy_text=shareJson.text;
        YiYi_APP.share(JSON.stringify(shareJson));
    }
}
//带链接的证书类型
function linkCertType(data) {
    var certLink="-";
    if (data.MainCertNo) {
        if (data.MainCertType == "GIA" || data.MainCertType == "IGI") {
            certLink="<a  class='cert_link_btn' href='#' data-href='/team/ViewCert?certType=" + data.MainCertType + "&certNo=" + data.MainCertNo + "' title='证书查询" + data.MainCertNo + "'>" + data.MainCertNo  + "</a>";
            // certLink='<a class="inlays_link" href="/cert/' + data.CertType.toLowerCase() + '/' + data.MainCertNo + '" target="_blank">'+data.MainCertNo+'</a>';
        }

    }
    return certLink;

}
//app证书链接
function app_linkCert(){
    var data=ItemJson;
    var App_json={};
    App_json.certType=data.MainCertType;
    App_json.certNumber=data.MainCertNo;
    App_json.url="http://apitest.checkgems.com:8200/api/v2/certs/"+data.MainCertType+"/"+data.MainCertNo;
    App_json.pdfUrl="http://apitest.checkgems.com:8200/api/v2/certs/"+data.MainCertType+"/"+data.MainCertNo+".pdf";
    YiYi_APP.showCertificate(JSON.stringify(App_json));
}

//付款
function formatReceiptStatus(val){
    if(val==0){
        return _("未支付");
    }else if(val==1){
        return _("已支付");
    }
}


//点击视频
var userAgent=navigator.userAgent;
$("#inlays_detail").on('click','.VideoBtn',function(){
    if(APP && userAgent.indexOf('Android')!=-1){
        // $("#video_div").show().css("display","none");
        $("#video_div").show().css("display","block");
    }else{
        $("#video_div").show().css("display","block");
    }
    $('#MainContent').hide();
    $("#look_img").hide();
    if(APP){
        var ProductVideo={};
        ProductVideo.url = $(this).attr('data-videos');
        YiYi_APP.showVideo(JSON.stringify(ProductVideo));
    }
})

// 点击图片icon
$("#inlays_detail").on("click",".ImgBtn",function(){
    if(APP && userAgent.indexOf('Android')!=-1){
        // $('#MainContent').hide();
        $('#MainContent').show();
    }else{
        $('#MainContent').show();
    }
    $("#look_img").show();
    $("#video_div").hide();

});



